package com.ruoyi.quartz.task;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.system.domain.SysStudent;
import com.ruoyi.system.service.ISysStudentService;
import org.springframework.stereotype.Component;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.SysStudent;
import com.ruoyi.system.service.ISysStudentService;

/**
 * 定时任务调度测试
 * 
 * @author ruoyi
 */
@Component("ryTask")
public class RyTask
{
    @Autowired
    private ISysStudentService sysStudentService;
    
    /**
     * 模拟学生数据并插入数据库
     */
    public void simulateStudentData()
    {
        try
        {
            System.out.println("开始执行学生数据模拟任务: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
            
            // 创建随机学生对象
            SysStudent student = createRandomStudent();
            
            // 插入数据库
            sysStudentService.insertSysStudent(student);
            
            System.out.println("学生数据模拟任务执行成功: " + student.getStudentName());
        }
        catch (Exception e)
        {
            System.err.println("学生数据模拟任务执行失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
    
    /**
     * 创建随机学生对象
     */
    private SysStudent createRandomStudent()
    {
        Random random = new Random();
        SysStudent student = new SysStudent();
        
        // 随机生成学生姓名（测试学生_数字）
        String[] names = {"张三", "李四", "王五", "赵六", "钱七", "孙八", "周九", "吴十"};
        String name = names[random.nextInt(names.length)] + "_" + random.nextInt(1000);
        student.setStudentName(name);
        
        // 随机性别
        student.setGender(random.nextBoolean() ? "0" : "1");
        
        // 随机生成个人介绍
        String[] majors = {"计算机科学", "软件工程", "数据科学", "人工智能", "信息安全"};
        String[] grades = {"大一", "大二", "大三", "大四"};
        String introduction = grades[random.nextInt(grades.length)] + "学生，专业：" + majors[random.nextInt(majors.length)];
        student.setIntroduction(introduction);
        
        // 设置头像地址
        student.setAvatar("/profile/avatar/default.jpg");
        
        // 设置状态为正常
        student.setStatus("0");
        
        // 设置删除标志为存在
        student.setDelFlag("0");
        
        // 设置创建者
        student.setCreateBy("system");
        
        // 设置创建时间
        student.setCreateTime(DateUtils.getNowDate());
        
        return student;
    }

    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
    {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params)
    {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams()
    {
        System.out.println("执行无参方法");
    }
}
